﻿using System.Web.Mvc;
using System.Collections;
using System.Web;
using System.IO;
using GBlog.Core.Service;
using GBlog.Core.Entities;
using GBlog.Core.Data;

namespace GBlog.Core.Service.Default
{
    public class ThemeService : ContentService<Theme>, IThemeService
    {
        public ThemeService(IRepository<Theme> Repository) : base(Repository) { }
        public void SetCurrentTheme(string theme)
        {
            if (!string.IsNullOrWhiteSpace(theme))
            {
                DependencyResolver.Current.GetService<IConfigService>().Current.Theme = theme;
                DependencyResolver.Current.GetService<IConfigService>().Save();
            }
        }

        public string GetThemeBaseURL(string theme)
        {
            if (!string.IsNullOrWhiteSpace(theme))
            {
                string physicalRoot = HttpContext.Current.Server.MapPath("~/themes/");
                if (Directory.Exists(Path.Combine(physicalRoot, theme)))
                {
                    return string.Format("~/themes/{0}/", theme);
                }
            }
            return "~/";
        }


        public string GetCurrentTheme()
        {
            return DependencyResolver.Current.GetService<IConfigService>().Current.Theme;
        }
    }
}